/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin;

import com.toedter.calendar.JDateChooser;
import connect.ConnectDatabase;
import java.awt.Color;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Thuan
 */
public class AddUser extends javax.swing.JFrame {
    
    
    /**
     * Creates new form AddUser
     */
    ConnectDatabase ketnoi;
    Connection con;
    
    public AddUser() {
        initComponents();
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyy HH:mm:ss");
        Date date = new Date();
        txtNgayTao.setText(dateFormat.format(date));
        txtMaThe.setText("13690");
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtDiaChi = new javax.swing.JTextField();
        rdNam = new javax.swing.JRadioButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtDanToc = new javax.swing.JTextField();
        rdNu = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        txtQuocTich = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtMaKhachHang = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtHoTen = new javax.swing.JTextField();
        txtNgaySinh = new javax.swing.JTextField();
        txtSDT = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtCMND = new javax.swing.JTextField();
        btMaKhachHang = new javax.swing.JLabel();
        btnHoTen = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        txtMaPin = new javax.swing.JTextField();
        txtSoTaiKhoan = new javax.swing.JTextField();
        cbLoaiThe = new javax.swing.JComboBox();
        txtNgayTao = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtMaThe = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        btnSoTaiKhoan = new javax.swing.JLabel();
        btnMaThe = new javax.swing.JLabel();
        btMaPin = new javax.swing.JLabel();
        btnLoaiThe = new javax.swing.JLabel();
        btnThem = new javax.swing.JButton();
        btnNhapMoi = new javax.swing.JButton();
        bntDong = new javax.swing.JButton();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setText("THÊM KHÁCH HÀNG");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin khách hàng"));

        jLabel6.setText("ĐỊA CHỈ");

        jLabel8.setText("SỐ ĐIỆN THOẠI");

        jLabel4.setText("NGÀY SINH");

        buttonGroup1.add(rdNam);
        rdNam.setText("Nam");

        jLabel5.setText("GIỚI TÍNH");

        jLabel3.setText("HỌ VÀ TÊN");

        buttonGroup1.add(rdNu);
        rdNu.setText("Nữ");

        jLabel2.setText("MÃ KHÁCH HÀNG");

        jLabel10.setText("QUỐC TỊCH");

        jLabel9.setText("DÂN TỘC");

        jLabel7.setText("SỐ CMND");

        btMaKhachHang.setForeground(new java.awt.Color(255, 51, 51));
        btMaKhachHang.setText("  ");

        btnHoTen.setForeground(new java.awt.Color(255, 0, 0));
        btnHoTen.setText("  ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addGap(39, 39, 39)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(txtDanToc, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtSDT, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtCMND, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(rdNam)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rdNu))
                    .addComponent(txtMaKhachHang, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtHoTen, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtDiaChi, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtQuocTich, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                    .addComponent(txtNgaySinh, javax.swing.GroupLayout.Alignment.LEADING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btMaKhachHang, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnHoTen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(txtMaKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btMaKhachHang))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnHoTen))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(rdNam)
                    .addComponent(rdNu))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtCMND, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtSDT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtDanToc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtQuocTich, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin tài khoản"));

        jLabel14.setText("LOẠI THẺ");

        cbLoaiThe.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "------", "t1", "t2", "t3", "t4" }));

        jLabel12.setText("MÃ THẺ");

        jLabel11.setText("SỐ TÀI KHOẢN");

        jLabel13.setText("MÃ PIN");

        jLabel15.setText("NGÀY TẠO");

        btnSoTaiKhoan.setForeground(new java.awt.Color(255, 0, 0));
        btnSoTaiKhoan.setText("  ");

        btnMaThe.setForeground(new java.awt.Color(255, 51, 51));
        btnMaThe.setText("  ");

        btMaPin.setForeground(new java.awt.Color(255, 0, 0));
        btMaPin.setText("  ");

        btnLoaiThe.setForeground(new java.awt.Color(255, 51, 51));
        btnLoaiThe.setText("  ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(cbLoaiThe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnLoaiThe, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtSoTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSoTaiKhoan))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtMaThe, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnMaThe, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtNgayTao, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtMaPin, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btMaPin, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtSoTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSoTaiKhoan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtMaThe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnMaThe))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtMaPin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btMaPin))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(cbLoaiThe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnLoaiThe))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtNgayTao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        btnThem.setText("Thêm");
        btnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemActionPerformed(evt);
            }
        });

        btnNhapMoi.setText("Nhập Mới");
        btnNhapMoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNhapMoiActionPerformed(evt);
            }
        });

        bntDong.setText("Đóng");
        bntDong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntDongActionPerformed(evt);
            }
        });

        jFormattedTextField1.setToolTipText("");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(btnThem)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btnNhapMoi)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(bntDong))
                                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(96, 96, 96)
                                .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnThem)
                            .addComponent(btnNhapMoi)
                            .addComponent(bntDong))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    // Nut them khach hang moi
    private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemActionPerformed
        CheckValidity checkValidity = new CheckValidity();
        
        ketnoi = new ConnectDatabase();
        con = ketnoi.connect();
        String strSQL = "{call sp_insert_KhachHang(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
        String gioitinh = null;
        boolean ktMKH = checkValidity.ktTonTai("KhachHang","MaKhachHang",txtMaKhachHang.getText().toString());
        boolean ktSTK = checkValidity.ktTonTai("TaiKhoan","SoTaiKhoan",txtSoTaiKhoan.getText().toString());
        boolean ktMT = checkValidity.ktTonTai("The","MaThe",txtMaThe.getText().toString());
        boolean hlNS = checkValidity.ktNgaySinh(txtNgaySinh.getText().toString());
        boolean hlMT = checkValidity.ktMaThe(txtMaThe.getText().toString());
        //Neu du lieu nhap vao khong thoa man thi ra thong bao
        
        if(txtMaKhachHang.getText().equals("") || txtHoTen.getText().equals("") || txtSoTaiKhoan.getText().equals("") || txtMaThe.getText().equals("") || txtMaPin.getText().equals("") || cbLoaiThe.getSelectedItem().toString().equals("------") || ktMKH || ktSTK || ktMT || !hlMT || !hlNS){
            //Kiem tra Mã Khách Hàng
            if(txtMaKhachHang.getText().equals("")){
                btMaKhachHang.setText("*");
                txtMaKhachHang.setBackground(Color.white);
            }else if(ktMKH){
                JOptionPane.showMessageDialog(null,"Mã Khách Hàng này đã có trong hệ thống!!!");
                btMaKhachHang.setText("*");
                txtMaKhachHang.setBackground(Color.yellow);
            }
            else{
                btMaKhachHang.setText("  ");
                txtMaKhachHang.setBackground(Color.white);
            }
            
            // Kiểm tra Họ Tên
            if(txtHoTen.getText().equals("")){
                btnHoTen.setText("*");
            }else {
                btnHoTen.setText("  ");
            }
            
            //kiểm tra ngày sinh
            if(!txtNgaySinh.getText().equals("")){
            if(!hlNS){
                JOptionPane.showMessageDialog(null, "Ngày sinh không đúng định dạng MM/dd/yyy");
                txtNgaySinh.setBackground(Color.yellow);
            }}else {txtNgaySinh.setBackground(Color.white);}
            
            // Kiểm tra Số Tài Khoản
            if(txtSoTaiKhoan.getText().equals("")){
                btnSoTaiKhoan.setText("*");
                txtSoTaiKhoan.setBackground(Color.white);
            }else if(ktSTK){
                JOptionPane.showMessageDialog(null,"Số Tài Khoản này đã có trong hệ thống!!!");
                btnSoTaiKhoan.setText("*");
                txtSoTaiKhoan.setBackground(Color.yellow);
            }else {
                btnSoTaiKhoan.setText("  ");
                txtSoTaiKhoan.setBackground(Color.white);
            }
            
            // Kiểm tra Mã Thẻ
            if(txtMaThe.getText().equals("")){
                btnMaThe.setText("*");
                txtMaThe.setBackground(Color.white);
            }else if(!hlMT){
                JOptionPane.showMessageDialog(null,"Mã Thẻ này không hợp lệ");
                btnMaThe.setText("*");
                txtMaThe.setBackground(Color.yellow);
            }else if(ktMT){
                JOptionPane.showMessageDialog(null,"Mã Thẻ này đã có trong hệ thống!!!");
                btnMaThe.setText("*");
                txtMaThe.setBackground(Color.yellow);
            }else {
                btnMaThe.setText("  ");
                txtMaThe.setBackground(Color.white);
            }
            
            //Kiểm tra Mã Pin
            if(txtMaPin.getText().equals("")){
                btMaPin.setText("*");
            }else {
                btMaPin.setText("  ");
            }
            
            //Kiểm tra Loại thẻ
            if(cbLoaiThe.getSelectedItem().toString().equals("------")){
                btnLoaiThe.setText("*");
            }else {
                btnLoaiThe.setText("  ");
            }

        }else{
        try {
            btMaKhachHang.setText("  ");
            btnHoTen.setText("  ");
            btnSoTaiKhoan.setText("  ");
            btnMaThe.setText("  ");
            btMaPin.setText("  ");
            btnLoaiThe.setText("  ");
            CallableStatement cs = con.prepareCall(strSQL);
            cs = con.prepareCall(strSQL);
            cs.setObject(1,txtMaKhachHang.getText());
            cs.setObject(2,txtHoTen.getText());
            cs.setObject(3,txtNgaySinh.getText());
            if(rdNam.isSelected()){
                gioitinh = "1";
            }else {
                gioitinh = "0";
            }
            cs.setObject(4,gioitinh);
            cs.setObject(5,txtDiaChi.getText());
            cs.setObject(6,txtCMND.getText());
            cs.setObject(7,txtSDT.getText());
            cs.setObject(8,txtDanToc.getText());
            cs.setObject(9,txtQuocTich.getText());
            cs.setObject(10,txtSoTaiKhoan.getText());
            cs.setObject(11,txtNgayTao.getText());
            cs.setObject(12,txtMaThe.getText());
            cs.setObject(13,txtMaPin.getText());
            cs.setObject(14,cbLoaiThe.getSelectedItem().toString());
            cs.execute();
        cs.close();
        con.close();
        txtMaKhachHang.setText(null);
        txtHoTen.setText(null);
        txtNgaySinh.setText(null);
        txtDiaChi.setText(null);
        txtCMND.setText(null);
        txtSDT.setText(null);
        txtDanToc.setText(null);
        txtQuocTich.setText(null);
        txtSoTaiKhoan.setText(null);
        txtMaThe.setText("13690");
        txtMaPin.setText(null);
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyy HH:mm:ss");
        Date date = new Date();
        txtNgayTao.setText(dateFormat.format(date));
        } catch (SQLException ex) {
            System.out.println("Khong the cap nhap");
        }
        }
        
    }//GEN-LAST:event_btnThemActionPerformed
    //Cai dat nut nhap lai nhap moi khach hang
    private void btnNhapMoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNhapMoiActionPerformed
        // TODO add your handling code here:
        txtMaKhachHang.setText(null);
        txtHoTen.setText(null);
        txtNgaySinh.setText(null);
        txtDiaChi.setText(null);
        txtCMND.setText(null);
        txtSDT.setText(null);
        txtDanToc.setText(null);
        txtQuocTich.setText(null);
        txtSoTaiKhoan.setText(null);
        txtMaThe.setText("13690");
        txtMaPin.setText(null);
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyy HH:mm:ss");
        Date date = new Date();
        txtNgayTao.setText(dateFormat.format(date));
    }//GEN-LAST:event_btnNhapMoiActionPerformed
    //Thoat chuong trinh
    private void bntDongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntDongActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_bntDongActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AddUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AddUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AddUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AddUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException ex) {
                Logger.getLogger(AddUser.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                Logger.getLogger(AddUser.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                Logger.getLogger(AddUser.class.getName()).log(Level.SEVERE, null, ex);
                } catch (UnsupportedLookAndFeelException ex) {
                Logger.getLogger(AddUser.class.getName()).log(Level.SEVERE, null, ex);
                }
                AddUser addUser = new AddUser();
                
                addUser.setLocationRelativeTo(null);
                addUser.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bntDong;
    private javax.swing.JLabel btMaKhachHang;
    private javax.swing.JLabel btMaPin;
    private javax.swing.JLabel btnHoTen;
    private javax.swing.JLabel btnLoaiThe;
    private javax.swing.JLabel btnMaThe;
    private javax.swing.JButton btnNhapMoi;
    private javax.swing.JLabel btnSoTaiKhoan;
    private javax.swing.JButton btnThem;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cbLoaiThe;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton rdNam;
    private javax.swing.JRadioButton rdNu;
    private javax.swing.JTextField txtCMND;
    private javax.swing.JTextField txtDanToc;
    private javax.swing.JTextField txtDiaChi;
    private javax.swing.JTextField txtHoTen;
    private javax.swing.JTextField txtMaKhachHang;
    private javax.swing.JTextField txtMaPin;
    private javax.swing.JTextField txtMaThe;
    private javax.swing.JTextField txtNgaySinh;
    private javax.swing.JTextField txtNgayTao;
    private javax.swing.JTextField txtQuocTich;
    private javax.swing.JTextField txtSDT;
    private javax.swing.JTextField txtSoTaiKhoan;
    // End of variables declaration//GEN-END:variables
}
